import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# 1. 读取CSV文件
df = pd.read_csv('original_data_0011.csv',skiprows=2)

# 2. 提取信号（假设列名如下，请根据实际文件调整列名）
time = df.iloc[:, 0].values  # 时间列（单位：秒）
ppg = df.iloc[:, 1].values   # PPG信号
ecg = df.iloc[:, 4].values   # ECG信号
abp = df.iloc[:, 3].values   # ABP信号

# 3. 计算采样率（假设时间戳是均匀间隔的）
fs =125 # 采样率（Hz）

# 4. 提取前60秒的数据
n_samples = int(60 * fs)
n_samples = min(n_samples, len(time))  # 确保不超过数据长度


# time_min = time[:n_samples]
# ppg_min = ppg[:n_samples]
# ecg_min = ecg[:n_samples]
# abp_min = abp[:n_samples]

time_min = time[n_samples:n_samples*2]
ppg_min = ppg[n_samples:n_samples*2]
ecg_min = ecg[n_samples:n_samples*2]
abp_min = abp[n_samples:n_samples*2]

# 5. 绘制三信号子图
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(15, 10), sharex=True)

# PPG信号
ax1.plot(time_min, ppg_min, color='blue', label='PPG')
ax1.set_ylabel('Amplitude')
ax1.set_title('PPG Signal (First 60 Seconds)')
ax1.grid(True, linestyle='--', alpha=0.6)
ax1.legend()

# ECG信号
ax2.plot(time_min, ecg_min, color='green', label='ECG')
ax2.set_ylabel('Amplitude')
ax2.set_title('ECG Signal (First 60 Seconds)')
ax2.grid(True, linestyle='--', alpha=0.6)
ax2.legend()

# ABP信号
ax3.plot(time_min, abp_min, color='red', label='ABP')
ax3.set_xlabel('Time (s)')
ax3.set_ylabel('Amplitude')
ax3.set_title('ABP Signal (First 60 Seconds)')
ax3.grid(True, linestyle='--', alpha=0.6)
ax3.legend()

plt.tight_layout()
plt.savefig('signals_plot.png', dpi=300)  # 保存为图片文件
print("图形已保存为 signals_plot.png")